#include "StdAfx.h"
#include "GridLine.h"
#include "UnitManager.h"

CGridLine::CGridLine(void)
{
	m_style	 = PS_DOT;
	m_width	 = 20;
	m_color	 = RGB(200,200,200);
}

CGridLine::CGridLine( int p_width )
:m_width(p_width)
{
	m_style	 = PS_DOT;
	m_color	 = RGB(200,200,200);
}

CGridLine::~CGridLine(void)
{
}

void CGridLine::draw( HWND p_hWnd, HDC p_dc  )
{
	RECT clientRect;

	//GetClientRect( p_hWnd, &clientRect );


	clientRect.left=clientRect.top=0;
	clientRect.right=CUnitManager::getPaintSize().cx;
	clientRect.bottom=CUnitManager::getPaintSize().cy;

	int startX = clientRect.left + m_width;
	int startY = clientRect.top  + m_width;

	HPEN hNewPen = ::CreatePen( m_style, 1, m_color );
	HPEN hOldPen = (HPEN)::SelectObject( p_dc, hNewPen );

	for( int i = startX; i < clientRect.right; i += m_width )
	{
		::MoveToEx( p_dc, i, 0, NULL );
		::LineTo( p_dc, i, clientRect.bottom );
	}

	for( int i = startY; i < clientRect.bottom; i += m_width )
	{
		::MoveToEx( p_dc, 0, i, NULL );
		::LineTo( p_dc, clientRect.right, i );
	}
	::SelectObject( p_dc, hOldPen );
	::DeleteObject(hNewPen);
}
